package org.colswedev.app.labhudson.control;

import java.util.Collection;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.colswedev.app.labhudson.dao.CustomerDAO;
import org.colswedev.app.labhudson.dao.DAO;
import org.colswedev.app.labhudson.entity.Customer;

/**
 * Clase encargada de controlar las operaciones CRUD de la entidad {@link org.colswedev.app.labhudson.entity.Customer}
 *
 * @author Leonardo Bohórquez
 */
public class CustomerControl {

    private EntityManagerFactory emf;
    private DAO<Customer> customerDAO;
    private static CustomerControl customerControl = null;

    private CustomerControl() {
	this.emf = Persistence.createEntityManagerFactory("LabHudsonGrupo4PU");
	customerDAO = new CustomerDAO(this.emf);
    }

    public static synchronized CustomerControl getInstance() {
	if (customerControl == null) {
	    customerControl = new CustomerControl();
	}
	return customerControl;
    }

    public boolean create(Customer toCreate) {
	return customerDAO.create(toCreate);
    }

    public boolean delete(Customer toDelete) {
	return customerDAO.delete(toDelete);
    }

    public boolean update(Customer toUpdate) {
	return customerDAO.update(toUpdate);
    }

    public Customer read(Customer toRead) {
	return customerDAO.read(toRead);
    }

    public Collection<Customer> readAll() {
	return customerDAO.readAll();
    }
}
